package com.zxhhyj.music.ui.screen.playlist

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Add
import androidx.compose.material.icons.rounded.MoreVert
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import com.zxhhyj.music.R
import com.zxhhyj.music.logic.repository.PlayListRepository
import com.zxhhyj.music.ui.common.EmptyStateBox
import com.zxhhyj.music.ui.item.PlayListItem
import com.zxhhyj.music.ui.screen.DialogDestination
import com.zxhhyj.music.ui.screen.ScreenDestination
import com.zxhhyj.music.ui.screen.SheetDestination
import com.zxhhyj.ui.view.AppCenterTopBar
import com.zxhhyj.ui.view.AppIconButton
import com.zxhhyj.ui.view.AppScaffold
import com.zxhhyj.ui.view.roundColumn
import dev.olshevski.navigation.reimagined.NavController
import dev.olshevski.navigation.reimagined.navigate


@Composable
fun PlayListScreen(
    mainNavController: NavController<ScreenDestination>,
    sheetNavController: NavController<SheetDestination>,
    dialogNavController: NavController<DialogDestination>,
    paddingValues: PaddingValues
) {
    AppScaffold(
        modifier = Modifier.fillMaxSize(),
        topBar = {
            AppCenterTopBar(
                title = { Text(text = stringResource(id = R.string.play_list)) },
                actions = {
                    AppIconButton(onClick = { dialogNavController.navigate(DialogDestination.CreatePlayList) }) {
                        Icon(
                            imageVector = Icons.Rounded.Add,
                            contentDescription = null
                        )
                    }
                })
        }) {
        EmptyStateBox(empty = PlayListRepository.playList.isEmpty()) {
            LazyColumn(modifier = Modifier.fillMaxSize(), contentPadding = paddingValues) {
                roundColumn {
                    items(PlayListRepository.playList) {
                        PlayListItem(
                            playListBean = it,
                            actions = {
                                AppIconButton(onClick = {
                                    sheetNavController.navigate(SheetDestination.PlaylistMenu(it))
                                }) {
                                    Icon(
                                        imageVector = Icons.Rounded.MoreVert,
                                        contentDescription = null,
                                    )
                                }
                            },
                            onClick = {
                                mainNavController.navigate(ScreenDestination.PlayListCnt(it.uuid))
                            })
                    }
                }
            }
        }
    }
}